# -*- coding: UTF-8 -*-
import os
import akshare as ak
from common import get_date

def action(config, run_date):
    # 解析配置文件
    conf = config['akshare']['stocks']['CN']
    level = conf['level']
    symbols = conf['symbols']

    # 存储目录校验
    file_path = 'data/akshare/stocks/CN'
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    
    if level == '5M':
        process_5m(symbols, file_path, run_date)
            
def process_5m(symbols, file_path, run_date):
    # 获取起始日期
    s_date = get_date(run_date, 29)
    for symbol in symbols:
        df = ak.index_zh_a_hist_min_em(symbol=symbol, period="5", start_date=f"{s_date} 09:30:00")
        df.to_csv(f'{file_path}/{symbol}-{run_date}-5M.csv')

    
def main():
    symbols = ['000300']
    file_path = '/tmp'
    run_date = '20241216'
    process_5m(symbols, file_path, run_date)


if __name__ == '__main__':
    main()

